home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13159 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: mutual data structures
  5. Date: 23 Mar 1996 21:14:02 GMT
  6. Organization: Pipeline USA
  7. Message-ID: <4j1piq$63d@news1.h1.usa.pipeline.com>
  8. References: <4j1mu1$fas@baskerville.CS.Arizona.EDU>
  9. NNTP-Posting-Host: 38.8.60.5
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 23, 1996 13:28:49 in article <mutual data structures>,
  16. 'kdb@CS.Arizona.EDU (Koen De Bosschere)' wrote: 
  17.  
  18.  
  19. >I am trying to create a data structure consisting of  
  20. >two linked lists, with nodes pointing at each other 
  21. >between the two lists.  
  22. >The problem is that in order to create typed pointers, I 
  23. >need the definition of the class, and no matter how I reorder 
  24. >the class definitions, there will always be an undefined 
  25. >class at some point. 
  26. >class node1 { 
  27. >.... 
  28. >node2 *pointer;   // node2 undefined at this point 
  29. >.... 
  30. >}; 
  31. >class node2 { 
  32. >.... 
  33. >node1 *pointer; 
  34. >.... 
  35. >}; 
  36. >I was wondering whether there is an elegant solution  
  37. >for this kind of problem. This kind of data structure 
  38. >cannot be so unusual, so other people must have faced 
  39. >this problem before. 
  40. Well, I don't know about elegancy, but the standard 
  41. solution is called "forward declaration".  Stick the following line 
  42. at the top of the file whose code you have included in this post: 
  43.  
  44. class node2; 
  45.  
  46. -- 
  47.  
  48. Pete Grant 
  49. Kalevi, Inc. 
  50. Sofware Engineering
  51.